<template>
    <div>
        <el-page-header @back="gotoback" title="返回">
            <template #content>
                <el-breadcrumb-item :to="{ path: '/organization' }">新增·组织</el-breadcrumb-item>
            </template>
        </el-page-header>
    </div>
    
    <div class="header">
        <el-form v-loading="load" style="width: 100%;height: 400px;" >
        <el-row>
            <el-col :span="12">
                <div class="back-ground wich">
                    <span class="span">名称</span>
                </div>
            </el-col>
            <el-col :span="12">
                <div class="back-ground wich">
                    <span class="span">等级</span>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
                <div class="back-ground">
                    <el-input v-model="name" placeholder="在此输入职务名称" clearable class="input" />
                </div>
            </el-col>
            <el-col :span="12">
                <div class="back-ground">
                    <el-input-number v-model="num" :min="1" :max="10" @change="handleChange" class="input" />
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div class="back-ground wich">
                    <span class="span">描述</span>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div class="ground">
                    <el-input v-model="textarea" :rows="2" type="textarea" placeholder="描述" style="margin-top: 10px;"/>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div class="back-ground wich">
                    <span class="span">操作</span>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <div class="ground">
                    <el-button type="primary" @click="add" style="margin-top: 3vh;float: left;margin-left: 2vh;">新增</el-button>
                </div>
            </el-col>
        </el-row>
    </el-form>
    </div>

</template>
<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'
import {AddZhiwu} from '../../../api/user/user'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router';

export default defineComponent({
    setup() {
        const router = useRouter();
        
        const data = reactive({
            load:false,
            num: 1,
            name: '',
            textarea:"",//描述
        })
        const events = {
            //返回上一级
            gotoback() {
                window.history.go(-1)
            },
            //等级
            handleChange() {

            },
            //新增
            add(){
                data.load=true
                AddZhiwu({
                    name:data.name,
                    lv:data.num,
                    explain:data.textarea
                }).then((res:any)=>{
                    console.log('新增组织---', res)
                    if (res.result == 0) {
                        ElMessage({
                            message: '添加成功',
                            type: 'success',
                            
                        })
                        data.load=false
                        router.push("/organization/zhiwu")
                    } else {
                        ElMessage({
                            message: '添加失败',
                            type: 'error',
                        })
                    }
                })
            }
        }
        return {
            ...events,
            ...toRefs(data)
        }
    },
})
</script>
<style scoped>
.header {
    border: #ccc solid 1px;
    margin-top: 3vh;
    border-radius: 5px;
}

.back-ground {
    border: #efebeb solid 1px;
    height: 50px;
}
.ground{
    border: #efebeb solid 1px;
    height: 70px;
}
.span {
    float: left;
    margin-top: 2vh;
    margin-left: 1vh;
    color: #c4c7d0;
}

.wich {
    background-color: rgba(240, 239, 245, 0.479);
}

.input {
    margin-top: 1vh;
    width: 70vh
}

.tag {
    float: left;
    margin-top: 2vh;
    margin-left: 5vh;
}
</style>
